package com.punch.user.controller;

import com.punch.common.model.Result;
import com.punch.common.page.PageInfo;
import com.punch.common.query.user.supplier.SupplierQueryInfo;
import com.punch.common.vo.user.supplier.SimpleSupplierVO;
import com.punch.common.vo.user.supplier.SupplierVO;
import com.punch.user.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 供应商控制层
 */
@RestController
@Api(tags = "供应商管理")
public class SupplierController {

    @Resource
    private SupplierService supplierService;

    /**
     * 供应商列表
     */
    @GetMapping("/suppliers")
    @ApiOperation(value = "供应商列表")
    public Result<PageInfo<SupplierVO>> listSupplier(@ModelAttribute SupplierQueryInfo queryInfo) {
        return Result.succeed(supplierService.queryPage(queryInfo));
    }

    /**
     * 新增供应商
     */
    @PostMapping("/supplier")
    @ApiOperation(value = "新增供应商")
    public Result<Long> saveSupplier(@RequestBody SupplierVO supplierVO) {
        return Result.succeed(supplierService.saveSupplier(supplierVO));
    }

    /**
     * 修改供应商
     */
    @PutMapping("/supplier")
    @ApiOperation(value = "修改供应商")
    public Result<Long> updateSupplier(@RequestBody SupplierVO supplierVO) {
        return Result.succeed(supplierService.updateSupplier(supplierVO));
    }

    /**
     * 获取供应商
     */
    @GetMapping("/supplier/{supplierId}")
    @ApiOperation(value = "获取供应商")
    public Result<SupplierVO> getSupplier(@PathVariable Long supplierId) {
        return Result.succeed(supplierService.getSupplier(supplierId));
    }


    /**
     * 删除供应商
     */
    @DeleteMapping("/supplier/{supplierId}")
    @ApiOperation(value = "删除供应商")
    public Result<Long> deleteSupplier(@PathVariable Long supplierId) {
        return Result.succeed(supplierService.deleteSupplier(supplierId));
    }

    /**
     * 供应商列表-简单信息
     */
    @GetMapping("/suppliers/simple")
    @ApiOperation(value = "供应商列表-简单信息")
    public Result<List<SimpleSupplierVO>> listSupplierSimple() {
        return Result.succeed(supplierService.listSupplierSimple());
    }
}
